
* correct 

program replace_one_dup
    * This is a small program to replace values of naics_import and
	args hs10_val naics_val
    // Check the inputs
    confirm integer number `hs10_val'

    replace naics = "`naics_val'" if commodity == `hs10_val'
end


program run_manual_crosswalk_corrections
    // This website is helpful for HS codes: https://hts.usitc.gov/

    // "Flour, meal, powder of fruit/nut, citrus or melon peel" becomes "Flour milling"
    replace_one_dup 1106300000 "311211"
    replace_one_dup 1106302000 "311211"
    replace_one_dup 1106304000 "311211"
    // "Homogenized preparations of meat and meat offal" goes to "All Other Miscellaneous Food Manufacturing" instead of "Specialty Canning"
    replace_one_dup 1602100000 "311999"
    // "Malt extract & limited cocoa pastrycooks products nes" goes to "Breweries" instead of "Flavoring Syrup and Concentrate Manufacturing" or "Spice and Extract Manufacturing"
    replace_one_dup 1901901000 "312120"
    replace_one_dup 1901901500 "312120"
    replace_one_dup 1901902000 "312120"
    // "Homogenized vegetable preparations, not frozen/vinega" and "Homogenised jams, jellies, etc" go to "Specialty Canning" instead of "All Other Miscellaneous Food Manufacturing"
    replace_one_dup 2005100000 "311422"
    replace_one_dup 2007100000 "311422"
    // "Apple juice not fermented or spirited" go to "Fruit and Vegetable Canning" instead of "Frozen Fruit, Juice, and Vegetable Manufacturing"
    replace_one_dup 2009710000 "311421"
    // "Homogenised composite food preparations" goes to "Specialty Canning" instead of "All Other Miscellaneous Food Manufacturing"
    replace_one_dup 2104200000 "311422"
    // "Vegetable oil-cake and other solid residues nes": "of corn" goes to "Wet Corn Milling"
    replace_one_dup 2306900020 "311221"
    // "Ethylene dibromide" goes to "All Other Basic Organic Chemical Manufacturing" instead of "All Other Basic Inorganic Chemical Manufacturing"
    replace_one_dup 2903310000 "325199"

    replace_one_dup 2921460000 "325192" // only duplicated for naics_import, moving duplicate from 325411
    replace_one_dup 3006700000 "325199" // only duplicated for naics_export, moving duplicate from 325611

    // Fertliziers goes to fertliziers broadly; 3100000000 is really a HS 2-digit
    replace_one_dup 3100000000 "32531X"

    // The following are matched only to 311611 (Animal (except Poultry) Slaughtering) for exports, but 311611 and 311610 (Animal Slaughtering and Processing) for imports
    replace_one_dup 4102102000 "311611" // sheep skins, with wool on
    replace_one_dup 4102292000 "311611" // sheep skins, without wool on, not pickled
    replace_one_dup 4103102000 "311611" // other hides?
    replace_one_dup 4103901200 "311611" // goat hides, vegetable pretanned

    // These are various types of largish-dimension heavy paper (>150g/m^2), and
    // the duplicates are all Paper (except Newsprint) Mills vs Paperboard Mills
    replace_one_dup 4802581000 "322121"  // Writing and cover paper
    replace_one_dup 4802582020 "322121"  // Drawing paper
    replace_one_dup 4802582040 "322130"  // Bristols
    replace_one_dup 4802582080 "322130"  // Other
    replace_one_dup 4802582095 "322130"  // Unclear, presumably "other"
    replace_one_dup 4802585000 "322121"  // Basic paper to be sensitized for use in photography
    replace_one_dup 4802586020 "322121" // Other, containing by weight 25 percent or more cotton fiber
    // Paper, Kraftliner, unbleached or otherwise go to paperboard, not paper
    replace_one_dup 4804110000 "322130"
    replace_one_dup 4804190000 "322130"

    // Kraft paper with weight between 150 and 225 g/m^2
    // (ISO standard is grammage over 250 -> paperboard)
    replace_one_dup 4804412000 "322121"
    replace_one_dup 4804414000 "322121"
    replace_one_dup 4804420010 "322121"
    replace_one_dup 4804420020 "322121"
    replace_one_dup 4804420030 "322121"
    replace_one_dup 4804420040 "322121"
    replace_one_dup 4804420050 "322121"
    replace_one_dup 4804490000 "322121"
    // Kraft paper with weight over 225 g/m^2
    replace_one_dup 4804510000 "322130" // unbleached
    replace_one_dup 4804520010 "322130" // milk carton stock
    replace_one_dup 4804520020 "322130" // folding carton stock
    replace_one_dup 4804520030 "322130" // Base stock for trays, dishes, plates, cups and the like
    replace_one_dup 4804520040 "322130" // Base stock for packaging
    replace_one_dup 4804520050 "322130" // Other
    replace_one_dup 4804590000 "322130" // Other heavy kraft paper
    replace_one_dup 4805122000 "322130" // Straw fluting paper > 150 g/m^2
    replace_one_dup 4805192000 "322130" // Non-straw fluting paper > 150 g/m^2
    replace_one_dup 4805250000 "322130" // Testliner > 150 g/m^2

    // This next chunk has weights < 150 g/m^2 or 150-225 g/m^2.
    // For all weights < 225, I'm classifing as paper, unless it's explicitly
    // a type of paperboard/carton board/pressboard/liner board etc
    replace_one_dup 4805911010 "322130" // Multi-ply folding carton board less than 150 g/m^2 -- counting as paper board because it's described as carton board
    replace_one_dup 4805911090 "322121" // Multi-ply paper and paperboard, <150 g/m^2, except folding carton board -- counting as paper because of its light weight
    replace_one_dup 4805922000 "322130" // Pressboard with weight 150-225 g/m^2
    replace_one_dup 4805924010 "322130" // Folding carton board with weight 150-225 g/m^2
    replace_one_dup 4805924020 "322121" // Construction paper with weight 150-225 g/m^2
    replace_one_dup 4805924030 "322130" // Liner board
    replace_one_dup 4805924040 "322121" // Other
    replace_one_dup 4805924055 "322121" // Unclear, presumably other

    // Same as HS6 480592, but for papers >225 g/m^2, so now "other" defaults to paper board
    replace_one_dup 4805932000 "322130" // Pressboard
    replace_one_dup 4805934010 "322130" // Folding carton board
    replace_one_dup 4805934015 "322130" // Wet machine board
    replace_one_dup 4805934020 "322121" // Construction paper
    replace_one_dup 4805934030 "322130" // Linerboard
    replace_one_dup 4805934040 "322130" // Unclear
    replace_one_dup 4805934055 "322130" // Unclear, presumably other
    // Laminated/composite papers and paperboards:
    replace_one_dup 4807001000 "322130" // internal tar lamination
    replace_one_dup 4807009100 "322130" // composite straw paper(board)
    replace_one_dup 4807009550 "322130"  // Other?
    // Paper and paperboard for writing or printing, various dimensions, weight > 150g/m^2, coated on one or both sides. Classifying as paper because of the "writing or printing" aspect.
    replace_one_dup 4810132010 "322121"
    replace_one_dup 4810132090 "322121"
    replace_one_dup 4810142010 "322121"
    replace_one_dup 4810142090 "322121"
    replace_one_dup 4810192010 "322121"
    replace_one_dup 4810192090 "322121"

    // Paper and paperboard, except for writing or printing, various dimensions,  coated on one or both sides. Classifying as paperboard for weights > 150 g/m^2 because of the "not writing or printing" aspect.
    replace_one_dup 4810311020 "322130" // < 150g/m^2 folding carton stock
    replace_one_dup 4810311040 "322130" // < 150g/m^2 stock for trays and dishes
    replace_one_dup 4810311050 "322121" // < 150g/m^2 gift wrap
    replace_one_dup 4810311060 "322121" // < 150g/m^2 ?
    replace_one_dup 4810311080 "322121" // < 150g/m^2 Other

    // Duplicates only for exports, 322121 vs 322222 (Coated and Laminated Paper Manufacturing)
    replace_one_dup 4810316500 "322121"
    replace_one_dup 4810316500 "322121"

    // Resuming previous list of paper and paperboard, not for printing:
    replace_one_dup 4810321020 "322130" // > 150g/m^2 folding carton stock
    replace_one_dup 4810321040 "322130" // > 150g/m^2 stock for trays and dishes
    replace_one_dup 4810321060 "322130" // > 150g/m^2 Other
    replace_one_dup 4810326500 "322130" // > 150g/m^2 Other (different size)

    // Other large coated paper/paperboard
    replace_one_dup 4810391200 "322130"
    replace_one_dup 4810391350 "322130"
    replace_one_dup 4810391400 "322130"
    replace_one_dup 4810396500 "322130"

    // Multi-ply, strips or rolls, weight above or below 150g/m^2
    replace_one_dup 4810921200 "322121"
    replace_one_dup 4810921350 "322121"
    replace_one_dup 4810921400 "322121"
    replace_one_dup 4810926500 "322121"

    // Other large-format paper/paperboard
    replace_one_dup 4810991000 "322121" // Parent of next three
    replace_one_dup 4810991010 "322121" // gift wrap paper
    replace_one_dup 4810991090 "322130" // folding carton
    replace_one_dup 4810996500 "322121" // Other

    // Tarred paper/paperboard, various sizes:
    replace_one_dup 4811101100 "322121"
    replace_one_dup 4811102100 "322121"

    // Paper/paperboard, bleached and covered with plastic, >150 g/m^2
    replace_one_dup 4811512010 "322130" // >150 g/m^2, > 0.3mm thick
    replace_one_dup 4811512020 "322130" // >150 g/m^2, > 0.3mm thick
    replace_one_dup 4811512030 "322130" // >150 g/m^2, > 0.3mm thick
    replace_one_dup 4811512060 "322130" // >150 g/m^2, > 0.3mm thick
    replace_one_dup 4811514000 "322121" // >150 g/m^2, < 0.3mm thick
    replace_one_dup 4811516000 "322130" // >150 g/m^2, small sizes

    // Duplicates of exports 322121 vs 322222; imports always 322121
    replace_one_dup 4811596000 "322121" // coated, other
    replace_one_dup 4811606000 "322121" // wax-coated
    replace_one_dup 4811909000 "322121" // other paper, tissue, thermal-coated, or lined (but see full description for details)

    // powders of iron or steel is going in "Iron and Steel Mills", not "Rolled Steel Shape Manufacturing"
    replace_one_dup 7205210000 "331111"
    replace_one_dup 7205290000 "331111"

    // The following corrections are cases where the import NAICS and export
    // NAICS differed, and I thought they shouldn't. This is a bit more of a
    // judgment call.
    replace_one_dup 2933330000 "325199" // use export naics of 325199 instead of import's 325411
    replace_one_dup 2934910000 "325199" // same
    replace_one_dup 2935006000 "325199" // same
    replace_one_dup 4101207000 "311611" // use export naics of 311611 instead of import's 311610
    replace_one_dup 4101507000 "311611" // same
    replace_one_dup 4101907000 "311611" // same
    replace_one_dup 4102103000 "311611" // same
    replace_one_dup 4102293000 "311611" // same
    replace_one_dup 4103103000 "311611" // same
    replace_one_dup 4103202000 "311611" // same
    replace_one_dup 4103203000 "311611" // same
    replace_one_dup 4103302000 "311611" // same
    replace_one_dup 4103901300 "311611" // same
    replace_one_dup 4103902000 "311611" // same
    replace_one_dup 4113200000 "311611" // same
    replace_one_dup 8101970000 "331419" // use export naics instead of import's listed non-NAICS of 910000
    replace_one_dup 8102970000 "331419" // same
    replace_one_dup 8108906010 "331419" // Wrought titanium, prefer export's primary production to import's secondary production
    replace_one_dup 8108906020 "331419" // slabs of titanium, same as above
    replace_one_dup 8109300000 "331419" // use export naics instead of import's listed non-NAICS of 910000
    replace_one_dup 8112220000 "331419" // same
    replace_one_dup 8112920500 "331419" // same
    replace_one_dup 8112920600 "331419" // same
    replace_one_dup 8112991000 "331419" // Germanium powder. Going with import's secondary production instead of export's primary
end

run_manual_crosswalk_corrections
program drop run_manual_crosswalk_corrections replace_one_dup


